﻿using MySql.Data.MySqlClient;
using SGV.Datos.Interfases;
using SGV.Entidad;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using DapperExtensions;


namespace SGV.Datos.Repositories
{
    public class LocalidadRepository : ILocalidadRepository
    {

        private IDbConnection _Db;

        public LocalidadRepository()
        {
            //constructor
        }


        public IList<Localidad> FindAll()
        {
            using (_Db = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySQL"].ToString()))
            {
                const string query = @"SELECT id, nombre FROM localidad";
                return _Db.Query<Localidad>(query).ToList();
            }
        }

        public IQueryable<Localidad> Find(Expression<Func<Localidad, bool>> predicate)
        {
            throw new NotImplementedException();
        }

        public Localidad FindById(int id)
        {
            using (_Db = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySQL"].ToString()))
            {
                const string query = @"SELECT id, proid, nombre FROM localidad WHERE proid = @proid";
                return this._Db.Query<Localidad>(query, new { proid = id }).SingleOrDefault();
            }
        }

        public int add(Localidad newEntity)
        {
            throw new NotImplementedException();
        }

        public bool remove(int id)
        {
            throw new NotImplementedException();
        }

        public int Modify(Localidad entity)
        {
            throw new NotImplementedException();
        }
    }
}
